package tech.aistar.controller;

import tech.aistar.service.IPhoneService;
import tech.aistar.service.impl.PhoneServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Ray
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/9/6  21:09
 */
@WebServlet(urlPatterns = "/phone/del/*")
public class PhoneDelAction extends HttpServlet {
    private IPhoneService phoneService = new PhoneServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pathInfo = req.getPathInfo();
        switch (pathInfo){
            case "/one":
                String id = req.getParameter("id");
                phoneService.delById(Integer.valueOf(id));
            case  "/any":
                String[] ids = req.getParameterValues("id");
                for (String s:ids){
                    phoneService.delById(Integer.valueOf(s));
                }
                break;
        }

        resp.sendRedirect(req.getContextPath()+"/phone/list");
    }
}
